﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 天离安卓权限维持系统.Services
{
    public class UpdateLister_Services
    {
        public static string Updata_Lister(string update)
        {
            string jsonFilePath = "listerner.json";
            Api.ListConfigApi.ListenerList listenerList;

            // 读取 JSON 数据
            try
            {
                listenerList = Services.Json_Services.ReadJson(jsonFilePath);
                if (listenerList != null)
                {
                    // 遍历所有监听器并将 listenStatus 更新为 "stop"
                    foreach (var listener in listenerList.Listeners)
                    {
                        listener.listenStatus = "stop";
                    }

                    // 将更新后的数据写回 JSON 文件
                    Services.Json_Services.WriteJson(jsonFilePath, listenerList);
                }
                else
                {
                    Console.WriteLine("监听列表为空，无法更新状态。");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("更新监听状态时发生异常：" + ex.Message);
            }
            return update;
        }
    }
}
